<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>个人潜在客户列表</title>
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" href="${ctxStatic}/bootstrap-table/bootstrap-table.css">
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/customer/potentialCustomer/">个人潜在客户列表</a></li>
	</ul>
	<form id="searchForm" action="${ctx}/customer/potentialCustomer/privateListAjaxData" method="post" class="breadcrumb form-search">
		<ul class="ul-form">
			<li><label>意向产品：</label>
				<sys:productType id="idProductType" name="targetProducts" withWu="true" withAll="true" defaultValue="" cssClass="select-medium" status="OPEN"></sys:productType>
			</li>
			<li><label>客户状态：</label>
				<sys:customerStatus id="customerStatusId" name="customerStatusId" withAll="true" defaultValue="" cssClass="select-medium"/>
			</li>
			<li><label>录入人员：</label>
				<sys:visibilityUser id="visibilityUserId" name="visibilityUserId" withAll="true" defaultValue="" cssClass="select-medium select2"/>
			</li>
			<li class="btns">
				<button type='button' class="btn btn-primary">查询 &nbsp;<i class="icon-search icon-white"></i></button>
			</li>
			<li class="clearfix"></li>
		</ul>
	</form>
	<table id="contentTable" data-url="${ctx}/customer/potentialCustomer/privateListAjaxData">
		<thead>
			<tr>
				<th colspan="13">
					<ul class="nav nav-toolbar">
						<c:if test="${sys_user_type eq 1}">
							<li><a id="aRecover" href="${ctx}/customer/potentialCustomer/recover">回收</a></li>
						</c:if>
						<c:if test="${fns:getUser().admin}">
							<li>|</li>
							<li><a id="aDel" href="${ctx}/customer/potentialCustomer/delete">删除</a></li>
						</c:if>
					</ul>
				</th>
			</tr>
			<tr>
				<th data-field="state" data-checkbox="true" data-align="center"></th>
				<th data-field="dataStatus" data-align="left" data-formatter="dataStatusFormatter">重复数据（新）</th>
				<th data-field="lastUpdated" data-align="left" >更新时间</th>
				<th data-field="corporationName" data-align="left" data-formatter="corporationNameFormatter" >公司名称</th>
				<th data-field="targetProducts" data-align="left" data-formatter="targetProductsFormatter" >产品意向</th>
				<th data-field="customerStatus" data-align="left" data-formatter="customerStatusFormatter" >客户状态</th>
				<th data-field="lastCustomerStatus" data-align="left" data-formatter="customerStatusFormatter" >上次客户状态</th>
				<th data-field="dateVisit" data-align="left">最后跟进时间</th>
				<th data-field="distStatus" data-align="left" data-formatter="distStatusFormatter" >分配状态</th>
				<th data-field="mobileOrPc" data-align="left" data-formatter="mobileOrPcFormatter" >来源设备</th>
				<th data-field="dateAppointment" data-align="left" >预约回访时间</th>
				<th data-field="isContact" data-align="left" data-formatter="isContactFormatter" >是否联系</th>
				<th data-field="visibilityUserName" data-align="left" >录入人员</th>
				<%--<th data-field="operate" data-align="left" data-formatter="operateFormatter" data-events="actionEvents" >操作</th>--%>
			</tr>
		</thead>
	</table>
	<script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
    <script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/bootstrap-table/config.js"></script>
    <script type="text/javascript">
		var selectTagMap={};
	    $(document).ready(function() {
	        //查询
	        $(".btn-primary").click(function () {
				refreshTableData();
	        });
			//初始化表格
	        $("#contentTable").bootstrapTable($.fn.BTConfigSimple({
	        	pageSize: 20,
	        	pageList: [20, 100, 300, 500],
				sortName: "a.last_updated",
				sortOrder: "desc",
				userQuery:function(){
					return $('#searchForm').refreshByForm().query;
				}
			}));

			//获取所有select值
			$("select").each(function(){
				var optionMap={};
				$(this).find("option").each(function(n,v){
					optionMap[v.value] = v.text;
				});
				selectTagMap[this.name]=optionMap;
			});
			//删除
			$("#aDel").click(function(){
				var thiz = this;
				if (!$("#contentTable").bootstrapTable('getSelections').length) {
					alertx("请选择需要删除的数据！");
					return false;
				}
				var ids = $.map($("#contentTable").bootstrapTable('getSelections'), function (row) {
					return row.id;
				});
				confirmx("确定删除选中的数据吗？",function(){
					$.ajax({
						url: thiz.href,
						type : "POST",
						data: {ids: ids.join(',')},
						dataType: "json",
						success : function(data){
							if (data.state) {
								alertx(data.message,function(){
									refreshTableData();
								},null,null,"info");
							} else {
								alertx(data.message,function(){
									refreshTableData();
								},null,null,"error");
							}
						},
						error: function(){
							alertx("发送请求失败，请稍后再试！",function(){
								refreshTableData();
							},null,null,"error");
						}
					});
				});
				return false;
			});
			//回收
			$("#aRecover").click(function(){
				var thiz = this;
				if (!$("#contentTable").bootstrapTable('getSelections').length) {
					alertx("请选择需要回收的数据！");
					return false;
				}
				var ids = $.map($("#contentTable").bootstrapTable('getSelections'), function (row) {
					return row.id;
				});
				confirmx("确定回收选中的数据吗？",function(){
					$.ajax({
						url: thiz.href,
						type : "POST",
						data: {ids: ids.join(',')},
						dataType: "json",
						success : function(data){
							if (data.state) {
								alertx(data.message,function(){
									refreshTableData();
								},null,null,"info");
							} else {
								alertx(data.message,function(){
									refreshTableData();
								},null,null,"error");
							}
						},
						error: function(){
							alertx("发送请求失败，请稍后再试！",function(){
								refreshTableData();
							},null,null,"error");
						}
					});
				});
				return false;
			});
			$(".addTab").live("click", function () {
				return window.parent.addTab($(this));
			});
		});

		function refreshTableData(){
			$("#contentTable").bootstrapTable('refresh',$('#searchForm').refreshByForm());
		}

		function corporationNameFormatter(value, row, index) {
			return "<a class='addTab' href='"+ctx+"/customer/potentialCustomer/detail?id="+row.id+"' target='mainFrame'>"+value+"</a>";
		}

		function targetProductsFormatter(value, row, index) {
			var optionMap=selectTagMap["targetProducts"];
			if(optionMap){
				return optionMap[value];
			}
		}

		function customerStatusFormatter(value, row, index) {
			var optionMap=selectTagMap["customerStatusId"];
			if(optionMap){
				return optionMap[value];
			}
		}

		function distStatusFormatter(value, row, index) {
			if (value&&value.toUpperCase()=="DISTED") {
				return "已分配";
			} else {
				return "未分配";
			}
		}
		function mobileOrPcFormatter(value, row, index) {
			if (value&&value.toLowerCase()=="mobile") {
				return "手机";
			} else {
				return "电脑";
			}
		}
		function dataStatusFormatter(value, row, index) {
			return row.mergerNum + "（<font color='red'>"+row.noReadMergerNum+"</font>）";
		}
		function isContactFormatter(value, row, index) {
        	if (row.visitNum && row.visitNum > 0) {
        		return "是";
        	} else {
        		return "否";
        	}
		}
		function operateFormatter(value, row, index) {
            return [
                '<a class="edit" href="javascript:void(0)" title="编辑">',
                '<i class="icon icon-edit"></i>',
                '</a>  ',
                '<a class="remove" href="javascript:void(0)" title="删除">',
                '<i class="icon icon-remove"></i>',
                '</a>'
            ].join('');
        }
		window.actionEvents = {
			'click .edit': function (e, value, row, index) {
                 alert('编辑这行: ' + JSON.stringify(row));
             },
             'click .remove': function (e, value, row, index) {
                 alert('删除这行: ' + JSON.stringify(row));
             }
		};
	</script>
</body>
</html>